<?php
/*********************************************************
author			Henson
date			2011-12-4
function		生成教程首页
*********************************************************/
include_once("../management/adminBase.php");

class TechIndex extends AdminBase{
	function index()
	{
		$sql = "select * from tbl_tech_cate where del_flg='0'";
		$this->db->setQuery($sql);
		$cateRows = $this->db->loadList();
		if(is_array($cateRows) && count($cateRows)>0)
		{
			foreach($cateRows as $key=>$value)
			{
				$sql = "select * from tbl_tech where cid='".$value['id']."' order by mTime desc limit 8";
				$this->db->setQuery($sql);
				$techRows = $this->db->loadList();
				if(is_array($techRows) && count($techRows)>0){
					foreach($techRows as $techK=>$techV)
					{
						$techRows[$techK]['link'] = 'http://www.87dianping.com/tech/'.$techV['id'].".html";
						$techRows[$techK]['date'] = date("Y-m",$techV['mTime']);
					}
					$cateRows[$key]['techRows'] = $techRows;
				}else{
					unset($cateRows[$key]);
				}
			}
		}
		$this->smarty->assign("cateRows",$cateRows);
		//热门文章
		$sql = "select id,title,from_unixtime(addTime,'%Y-%m')as addTime from tbl_tech where del_flg='0' and published='1' order by upNum desc limit 10";
		$this->db->setQuery($sql);
		$hotRows = $this->db->loadList();
		$this->smarty->assign("hotRows",$hotRows);
		//最新文章
		$sql = "select id,title,from_unixtime(addTime,'%Y-%m')as addTime from tbl_tech where del_flg='0' and published='1' order by addTime desc limit 10";
		$this->db->setQuery($sql);
		$newRows = $this->db->loadList();
		$this->smarty->assign("newRows",$newRows);

		$this->smarty->assign("template_name",'tech_index.tpl');
		$pageMain = $this->smarty->fetch("layout.tpl");
		$filename = _TECH_PATH."index.html";
		writeFile($pageMain, $filename);
		header("Content-Type:text/html; charset=utf-8");
		echo "教程页面已生成！&nbsp;&nbsp;&nbsp;<a href='/tech/index.html' target='_blank'>查看</a>";die;
	}
}

$techIndex = new TechIndex();
?>